package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.YhMember;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.vo.YhMemberWithdrawalRecordsVo;
import com.ruoyi.system.service.IYhMemberService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YhMemberWithdrawalRecords;
import com.ruoyi.system.service.IYhMemberWithdrawalRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户提现记录Controller
 * 
 * @author ruoyi
 * @date 2023-06-06
 */
@Api(tags = "用户提现记录管理")
@RestController
@RequestMapping("/yh/withdrawal/record")
public class YhMemberWithdrawalRecordsController extends BaseController
{
    @Autowired
    private IYhMemberWithdrawalRecordsService yhMemberWithdrawalRecordsService;
    @Autowired
    private IYhMemberService yhMemberService;

    /**
     * 查询用户提现记录列表
     */
    @ApiOperation("获取用户提现记录列表")
    @GetMapping("/list")
    public TableDataInfo withdrawalRecordsList(YhMemberWithdrawalRecords yhMemberWithdrawalRecords)
    {
        startPage();
        List<YhMemberWithdrawalRecordsVo> list = yhMemberWithdrawalRecordsService.withdrawalRecordsList(yhMemberWithdrawalRecords);
        return getDataTable(list);
    }

    /**
     * 用户查询自己的提现记录列表
     */
    @ApiOperation("用户查询自己的提现记录列表")
    @GetMapping("/listByMember")
    public TableDataInfo listByMember(YhMemberWithdrawalRecords yhMemberWithdrawalRecords)
    {
        startPage();
        yhMemberWithdrawalRecords.setMemberId(SecurityUtils.getUserId().toString());
        QueryWrapper<YhMemberWithdrawalRecords> queryWrapper = yhMemberWithdrawalRecords.queryWrapper();
        Date createTime = yhMemberWithdrawalRecords.getCreateTime();
        // 时间范围
        if(StringUtils.isNotNull(createTime)) {
            String beginTime = DateUtils.dateTime(createTime);
            queryWrapper.ge("create_time", beginTime + " 00:00:01")
                    .le("create_time", DateUtils.getLastday(beginTime.substring(0, 4), beginTime.substring(5, 7)) + " 23:59:59");
        }
        List<YhMemberWithdrawalRecords> list = yhMemberWithdrawalRecordsService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出用户提现记录列表
     */
    @ApiOperation("导出用户提现记录列表")
    @PreAuthorize("@ss.hasPermi('yh:withdrawalrecords:export')")
    @Log(title = "用户提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhMemberWithdrawalRecords yhMemberWithdrawalRecords)
    {
        List<YhMemberWithdrawalRecords> list = yhMemberWithdrawalRecordsService.list(yhMemberWithdrawalRecords.queryWrapper());
        ExcelUtil<YhMemberWithdrawalRecords> util = new ExcelUtil<YhMemberWithdrawalRecords>(YhMemberWithdrawalRecords.class);
        util.exportExcel(response, list, "用户提现记录数据");
    }

    /**
     * 获取用户提现记录详细信息
     */
    @ApiOperation("获取用户提现记录详细")
    @ApiImplicitParam(name = "id", value = "用户提现记录ID", required = true, dataType = "String", paramType = "path")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        YhMemberWithdrawalRecords byId = yhMemberWithdrawalRecordsService.getById(id);
        YhMember yhMember = yhMemberService.getById(byId.getMemberId());
        byId.setNickName(yhMember.getNickName());
        return success(byId);
    }

    /**
     * 新增用户提现记录
     */
    @ApiOperation("新增用户提现记录")
    @Log(title = "用户提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addWithdrawalRecords(@RequestBody YhMemberWithdrawalRecords yhMemberWithdrawalRecords)
    {
        return toAjax(yhMemberWithdrawalRecordsService.addWithdrawalRecords(yhMemberWithdrawalRecords));
    }

    /**
     * 审核用户提现记录
     */
    @ApiOperation("审核用户提现记录")
    @PreAuthorize("@ss.hasPermi('yh:withdrawalrecords:edit')")
    @Log(title = "用户提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult withdrawalProcess(@RequestBody YhMemberWithdrawalRecords yhMemberWithdrawalRecords)
    {
        return toAjax(yhMemberWithdrawalRecordsService.withdrawalProcess(yhMemberWithdrawalRecords));
    }

    /**
     * 删除用户提现记录
     */
    @ApiOperation("删除用户信息")
    @ApiImplicitParam(name = "ids", value = "用户提现记录ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('yh:withdrawalrecords:remove')")
    @Log(title = "用户提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(yhMemberWithdrawalRecordsService.removeByIds(ids));
    }
}
